import sys
from Ui_main import *
from PyQt4 import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qwt5.qplt import *
from Numeric import *
from numpy import *


class tab1():
    def  __init__(self, kanal):
        self.k = kanal
    
    def OtvorSubor(self, kanal):
        row = 0
        i=0
        subor = QtGui.QFileDialog.getOpenFileName(self, '/home', '*.*')
        self.ui.lineK1.setText(subor)
        f = open(subor, 'r')
        k = loadtxt(f)
        
        for line in k:
            if self.ui.tabMag.rowCount() < row:
                self.ui.tabMag.insertRow(row)
            elif self.ui.tabMag.rowCount() == row:
                self.ui.tabMag.insertRow(row)
            
            self.ui.tabMag.setItem(row, kanal-1, QTableWidgetItem(str(line)))
           # print line
            row = row + 1
            
        
        
        self.grid = QwtPlotGrid()
        self.grid.enableXMin(True)
        self.grid.setMajPen(QPen(Qt.white, 0, Qt.DotLine))
        self.grid.setMinPen(QPen(Qt.gray, 0 , Qt.DotLine))
        
        
        self.curve = QwtPlotCurve("K"+kanal)
        
        self.curve.setPen(QPen(Qt.red))
        r = arange(0,  len(k), 1)
        
        self.curve.setData(r, k)
        self.ui.qPlot.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)
        
        
        
        self.curve.attach(self.ui.qPlot)
         
        self.ui.qPlot.replot()   
            
        f.close()
   
    
   


    
